// SPDX-FileCopyrightText: 2024 KylinSoft Co., Ltd.
//
// SPDX-License-Identifier: GPL-1.0-or-later

#pragma once

#include "qwayland-ukui-shell.h"
#include "qwayland-xdg-shell.h"

#include "xdgdecorationv1.h"

#include <QRegion>

#include <memory>

namespace QtWaylandClient
{

class QWaylandDisplay;
class QWaylandWindow;
class Popup;
class Toplevel;
class UkuiBlurManager;
class UkuiShellSurface;
class XdgDialogWmV1;
class XdgActivationV1;
class KdeSlideManager;

class UkuiShell : public QtWayland::ukui_shell, public QtWayland::xdg_wm_base
{
public:
    UkuiShell(QWaylandDisplay *display, uint32_t id, uint32_t availableVersion);
    ~UkuiShell() override;

    XdgDecorationManagerV1 *decorationManager();
    XdgDialogWmV1 *xdgDialogWm();
    XdgActivationV1 *xdgActivation();
    UkuiBlurManager *blurManager();
    KdeSlideManager *slideManager();

    Popup *topmostGrabbingPopup();
    void setTopmostGrabbingPopup(Popup *popup);

    UkuiShellSurface *getUkuiShellSurface(QWaylandWindow *window);

protected:
    void xdg_wm_base_ping(uint32_t serial) override;

private:
    static void handleRegistryGlobal(void *data, ::wl_registry *registry, uint id,
                                     const QString &interface, uint version);

    QWaylandDisplay *m_display = nullptr;

    std::unique_ptr<XdgDecorationManagerV1> m_xdgDecorationManager;
    std::unique_ptr<XdgDialogWmV1> m_xdgDialogWm;
    std::unique_ptr<XdgActivationV1> m_xdgActivation;
    std::unique_ptr<UkuiBlurManager> m_blurManager;
    std::unique_ptr<KdeSlideManager> m_slideManager;

    Popup *m_topmostGrabbingPopup = nullptr;
};
}